{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>商品列表</h5>
        </div>
        <div class="ibox-content">
            <!--搜索框开始-->           
            <div class="row">
                <div class="col-sm-12">   
                <div  class="col-sm-2" style="width: 100px">
                    <div class="input-group" >  
                        <a href="{:url('add_goods')}"><button class="btn btn-primary" type="button">添加商品</button></a>
                    </div>
                </div>                                                                    
                </div>
            </div>
            <!--搜索框结束-->
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="table table-bordered table-hover">
                        <thead>
                            <tr class="long-tr">
                                <th>ID</th>
                                <th width="15%">商品名称</th>
                                <th width="7%">商品类型</th>
                                <th width="15%">图片</th>
                                <th width="7%">价格</th>
                                <th width="7%">数量</th>
                                <th width="15%">描述</th>
                                <th width="7%">是否推荐</th>
                                <th width="7%">是否上架</th>
                                <th width="15%">添加时间</th>
                                <th width="12%">操作</th>
                            </tr>
                        </thead>
                        <tbody id="article_list">
                            {foreach name="lists" item="vo"}
                                <tr class="long-td">
                                    <td>{$vo.id}</td>
                                    <td>{$vo.goods_name}</td>
                                    {if condition="$vo['target_type'] == 1"}
                                    <td>宝箱</td>
                                    {else/}
                                    <td>道具</td>
                                    {/if}
                                    <td><img src="{$vo.goods_thumb}" style="height: 30px" onerror="this.src='/static/admin/images/no_img.jpg'"/></td>
                                    <td>{$vo.goods_price}</td>
                                    <td>{$vo.goods_number}</td>
                                    <td>{$vo.goods_desc}</td>
                                    {if condition="$vo['is_best'] == 1"}
                                    <td>
                                        <a href="javascript:;" onclick="goods_state({$vo.id},0);">
                                        <div id="zt{$vo.id}"><span class="label label-danger">点击取消</span></div>
                                        </a>
                                    </td>
                                    {else/}
                                    <td>
                                        <a href="javascript:;" onclick="goods_state({$vo.id},1);">
                                            <div id="zt{$vo.id}"><span class="label label-info">点击推荐</span></div>
                                        </a>
                                    </td>
                                    {/if}

                                    {if condition="$vo['status'] == 1"}
                                    <td>
                                        <a href="javascript:;" onclick="goods_status({$vo.id},0);">
                                            <div id="zt{$vo.id}"><span class="label label-danger">点击下架</span></div>
                                        </a>
                                    </td>
                                    {else/}
                                    <td>
                                        <a href="javascript:;" onclick="goods_status({$vo.id},1);">
                                            <div id="zt{$vo.id}"><span class="label label-info">点击上架</span></div>
                                        </a>
                                    </td>
                                    {/if}
                                    <td>{$vo.create_time|date="Y-m-d H:i:s",###}</td>
                                    <td>
                                        <a href="{:url('edit_goods',['id'=>$vo.id])}" class="btn btn-primary btn-xs">
                                            <i class="fa fa-paste"></i> 编辑</a>&nbsp;&nbsp;
                                        <a href="javascript:;" onclick="del_goods({$vo.id})" class="btn btn-danger btn-xs">
                                            <i class="fa fa-trash-o"></i> 删除</a>   
                                    </td>
                                </tr>
                            {/foreach}
                        </tbody>
                    </table>
                </div>
                <!-- 分页 -->
                <div id="Pages">  {$page} </div>
            </div>
        </div>
    </div>
</div>
<!-- End Panel Other -->
</div>
{include file="public/footer" /}


<script type="text/javascript">
    function goods_state(val,is_best){
        $.post('{:url("goods_state")}',
            {id:val,is_best:is_best},
            function(res){
                layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
                    window.location.href="{:url('goods/index')}";
                });
            });
        return false;
    }
    function goods_status(val,status){
        $.post('{:url("goods_status")}',
            {id:val,status:status},
            function(res){
                layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
                    window.location.href="{:url('goods/index')}";
                });
            });
        return false;
    }

    function del_goods(id){
        layer.confirm('确认删除此数据?', {icon: 3, title:'提示'}, function(index){
            //do something
            $.getJSON("{:url('del_goods')}", {'id' : id}, function(res){
                if(res.code == 1){
                    layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
                        window.location.href="{:url('goods/index')}";
                    });               
                }else{
                    layer.msg(res.msg,{icon:0,time:1500,shade: 0.1});
                }
            });

            layer.close(index);
        })

    }
</script>
</body>
</html>